package org.loneranger.p6_initialization;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class InitService implements InitializingBean {

    private InitUser initUser;

    public InitService() {
        System.out.println("构造函数");
    }

    @Autowired
    public void setInitUser(InitUser initUser) {
        this.initUser = initUser;
        System.out.println("属性填充 - set注入");
    }

    /**
     * @PostConstruct 利用了初始化前的逻辑去处理 - 它也对应了一个beanPostProcessor
     */
    @PostConstruct
    public void xxx() {
        System.out.println("xxx");
    }

    /**
     * 实现 InitializingBean 接口，重新afterPropertiesSet方法，可以在该方法中对bean的初始化进行干涉
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("初始化 - afterPropertiesSet");
    }
}
